package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.MonitorPhoneReply;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeMonitorPhone implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *TJ,2020916301,V4,MONITOR,173030,13912345678,status,050315,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[4];
        String phoneNumber=split[5];//被监听的手机号码
        String status = split[6];//监听结果 1-成功
        String deviceTime = split[7];//时分秒时间
        String lat = split[9];
        String lng = split[11];
        String speed = split[13];
        String orientation = split[14];
        String deviceDate = split[15];//年月日
        String deviceStatus = split[16];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        MonitorPhoneReply monitorPhoneReply = new MonitorPhoneReply();
        monitorPhoneReply.setCommandNumber(commandNumber);
        monitorPhoneReply.setDeviceDate(deviceDate);
        monitorPhoneReply.setDeviceTime(deviceTime);
        monitorPhoneReply.setImei(imei);
        monitorPhoneReply.setDeviceStatus(deviceStatus);
        monitorPhoneReply.setPhone(phoneNumber);
        monitorPhoneReply.setResult(Integer.parseInt(status));
        monitorPhoneReply.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_SET_MONITOR_PHONE,false,"",monitorPhoneReply);
    }
}
